from time import sleep
from tkinter import ttk, Button
from tkinter import *
from ModeType.Base import BaseOutput
from pynput import mouse

# 鼠标点击控制

class MouseClickResult(BaseOutput):
    def createConfig(self, root):
        box = ttk.LabelFrame(root, text='鼠标点击')
        box.pack(padx=10, pady=10)

        row = 0
        ttk.Label(box, text='输出速度(毫秒)').grid(row=row, column=0)
        self.speed = Scale(box, from_=50, to=5000, orient=HORIZONTAL, length=500)
        self.speed.grid(row=row, column=1, sticky=W+E+N+S)
        self.speed.set(100)

        row += 1
        ttk.Label(box, text='输出次数').grid(row=row, column=0)
        self.count = ttk.Spinbox(box, from_=1)
        self.count.grid(row=row, column=1, pady=4, sticky=W+E+N+S)
        self.count.set(1)

        row += 1
        countNum = IntVar(value=0)
        countBox = ttk.Spinbox(box, from_=0)
        countBox.grid(row=row, column=2)
        countBox.set(countNum.get())
        def click_handle():
            countNum.set(countNum.get() + 1)
            countBox.set(countNum.get())
            print('点击了', countNum.get())
        ttk.Label(box, text='测试点击').grid(row=row, column=0)
        Button(box, text='鼠标放上来测试吧', command=click_handle).grid(row=row, column=1)

        return box

    def run(self):
        index = 0
        count = self.get_count()
        speed = self.get_speed()
        while index < count:
            if self.stop:
                break
            mouse.Controller().click(mouse.Button.left, 1)
            index += 1
            sleep(speed)
